<include file="header" />

<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/base/repair/images/load-bee.png"/>
    </div>
    <div class="top">
        <p>
        	<a href="javascript:void(0)" class="iconfont icon-zuo fl-left"></a>
        	注册
        	<a href="{BEESCRM::U('base/user/register',array('account_id'=>$accountId))}" class="iconfont icon-shouye fl-right"></a>
        </p>
    </div>
    <div class="checkbox">
        <p class="checked" data-type="0"><span class="iconfont icon-xuanzedianjihou"></span> 账号</p>
    </div>
	<div class="contain actived">
		<p class="title">身份选择</p>
		<p class="form-box">
			<select id="role" class="input">
				<option value="0">学生</option>
				<option value="1">教职工</option>
				<option value="2">来宾</option>
			</select>
		</p>
		<p class="title">学号</p>
		<p class="form-box">
			<input class="input" id="number" value="{BEESCRM:$res['number']}" placeholder="例如：2015010101" />
		</p>
		<p class="title">姓名</p>
		<p class="form-box">
			<input class="input" id="username" value="{BEESCRM:$res['username']}"/>
		</p>
		<p class="title">手机</p>
		<div class="form-box">
			<input class="input" id="mobile" value="{BEESCRM:$res['mobile']}"/>
			<!--<a href="javascript:;" class="get-msg" id="get-msg">获取验证码</a>-->
		</div>
		<!--<p class="title">验证码</p>
		<p class="form-box">
			<input class="input" id="code" value=""/>
		</p>-->
		<div class="school" >
			<p class="title">学校</p>
			<p class="form-box">
				<select class="select" id="school">
					<option value="0">学校名称</option>
					<volist name="school" id="vo">
						<option value="{BEESCRM:$vo.school_id}">{BEESCRM:$vo.school_name}</option>
					</volist>
				</select>
			</p>
		</div>
        <if condition="$remark">
            <div class="contain wraper wraper-btm">
                <p class="field" style="padding: 0 10px;"><span style="color: red;">{BEESCRM:$remark}</span></p>
            </div>
        </if>
	</div>
	<div class="marginb-50"></div>
	<div class="btn-box">
		<input type="hidden" id="register_id" value="{BEESCRM:$res['register_id']}">
		<a href="#" class="btn big" id="addAddr">提交</a>
	</div>

</div>
<include file="commonJS" />
<script>
	//点击获取验证码
	var verifyTag = true;
	$('.form-box').on('click', '#get-msg', function (e) {
		e.preventDefault();
		if(verifyTag) getCode('#get-msg');
		else return;
	});
	function getCode(elem) {
		var data={};
		data.mobile = $('#mobile').val();
		var verify=/^(?:13\d|15\d|18\d|17\d|14\d)\d{5}(\d{3}|\*{3})$/;
		if (!verify.test(data.mobile)) {
			$.alert('error','请输入正确的手机号码');
        	return false;
		}else{
			var json={};
            json.url="{BEESCRM::U('base/User/getCode',array('account_id'=>$accountId))}";
            json.data=data;
            json.method='post';
			$.getAjax(json, true, timeCountDown(elem), '');
		}
	}
	// 验证倒计时
	function timeCountDown(elem, seconds) {
		verifyTag = false;
		if(typeof seconds == undefined || seconds == null) seconds = 60;
		setTimeout(function () {
			if(seconds > 0) {
				seconds--;
				$(elem).text('已发送 ' + seconds + 's').addClass('disabled');
				timeCountDown(elem, seconds);
			} else {
				$(elem).removeClass('disabled').text('获取验证码');
				verifyTag = true;
			}
		}, 1000);
	}



    $('#addAddr').on('click',function(){
    	var data={};
		var verify_method = /^(?:13\d|15\d|18\d|17\d|14\d)\d{5}(\d{3}|\*{3})$/;
    	data.mobile=$('#mobile').val();
    	data.number=$('#number').val();
        data.real_name = $('#username').val();
        data.school_id = $('#school').val();
        data.register_id=$('#register_id').val();
        //data.code=$('#code').val();
        data.role=$('#role').val();
        data.status=0;
        data.type=0;

        if (!data.number || data.number.length>15) {
        	$.alert('error','请输入正确的学号');
        	return false;
       	} else if (!data.real_name) {
       		$.alert('error','姓名不能为空');
       		return false;
        }else if(!data.mobile){
	        $.alert('error','手机号不能为空');
	        return false;
	    }else if (!verify_method.test(data.mobile)) {
        	$.alert('error','请输入正确的手机号');
        	return false;
        }/*else if (!code) {
        	$.alert('error','请输入验证码');
        	return false;
        }*/else if (data.school_id== 0){
	        $.alert('error','请选择学校');
	        return false;
        }else {
            var json={};
            json.url="{BEESCRM::U('base/User/doRegister',array('account_id'=>$accountId))}";
            json.data=data;
            json.method='post';
			$.getAjax(json, true, reload, '');
        }
    });

    function reload(data){
        var type = data.type;
        location.href="{BEESCRM::U('/base/User/tips',array('account_id'=>$accountId))}/type/"+type;
	}

    $("#role").change(function () {
    	var id=$('#role').val();
    	if(id==0){
    		location.href ="{BEESCRM::U('base/user/register',array('account_id'=>$accountId,'type'=>0))}";
        } else if(id==1) {
            location.href = "{BEESCRM::U('base/user/register',array('account_id'=>$accountId,'type'=>1))}";
        } else if(id==2) {
        	location.href ="{BEESCRM::U('base/user/register',array('account_id'=>$accountId,'type'=>2))}";
        }
    });
</script>
</body>
</html>